define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'banner/banners/index' + location.search,
                    add_url: 'banner/banners/add',
                    edit_url: 'banner/banners/edit',
                    del_url: 'banner/banners/del',
                    multi_url: 'banner/banners/multi',
                    import_url: 'banner/banners/import',
                    table: 'banners',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        // {field: 'weigh', title: __('Weigh'), operate: false},
                        // {field: 'url', title: __('Url'), operate: 'LIKE', formatter: Table.api.formatter.url},
                        {field: 'type', title: __('Type'), searchList: {"0":__('Type 0'),"1":__('Type 1')}, formatter: Table.api.formatter.normal},
                        // {field: 'type_url', title: __('Type_url'), searchList: {"1":__('Type_url 1'),"2":__('Type_url 2'),"3":__('Type_url 3')}, formatter: Table.api.formatter.url},
                        // {field: 'type_id', title: __('Type_id')},
                        {field: 'user_id', title: __('购买人ID'),operate: false},
                        {field: 'nickname', title: __('购买人'),operate: false},
                        // {field: 'buy_time', title: __('Buy_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'banner_price_id', title: __('Banner_price_id')},
                        {field: 'status', title: __('Status'),searchList: {"0":__('Status 0'),"1":__('Status 1')}, formatter: Table.api.formatter.status},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'provincial_isd', title: __('Provincial_id')},
                        // {field: 'user_id', title: __('User_id')},
                        {field: 'ex_status', title: __('上传审核'), searchList: {"0":__('审核中'),"1":__('审核通过'),"2":__('拒绝审核')}, formatter: Table.api.formatter.status},

                        // {field: 'end_time', title: __('End_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'provincial.name', title: __('省份'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,



                            buttons:[
                                {
                                    name: 'plus',
                                    title: __('通过审核'),
                                    classname: 'btn btn-xs btn-success btn-ajax',
                                    icon: 'fa fa-check',
                                    extend: 'data-area=\'["70%", "80%"]\' data-shade=\'[0.5, "#000"]\'',
                                    // url: 'work_order/state?status=complete',
                                    confirm: '确定通过审核吗',

                                    url: function (row) {
                                        return 'banner/banners/examine?ids='+row.id;
                                    },
                                    success: function (data, ret) {
                                        $(".btn-refresh").trigger("click");
                                    },
                                    visible: function (row) {
                                        if (row.ex_status == '0') {
                                            return true;
                                        }
                                    }
                                },
                                {
                                    //不通过审核 代码逻辑尚未完善
                                    name: 'plus',
                                    title: __('不通过审核'),
                                    classname: 'btn btn-xs btn-danger   btn-dialog',
                                    icon: 'fa fa-close',
                                    extend: 'data-area=\'["30%", "40%"]\' data-shade=\'[0.5, "#000"]\'',
                                    url: function (row) {
                                        return 'banner/banners/failed?ids='+row.id;
                                    },
                                    success: function (data, ret) {
                                        $(".btn-refresh").trigger("click");
                                    },
                                    visible: function (row) {
                                        if (row.ex_status == '0') {
                                            return true;
                                        }

                                    }
                                },
                            ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },

        failed: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
